if [ -f ~/.bashrc.local ]; then
  . ~/.bashrc.local
fi

if [ "$TERM" == "dumb" ]; then
  cd $PROJ
fi

alias bargs="function _bargs () { echo arg_one \$1 ; echo arg_two \$2 ; echo all_args \$* ; echo files_dirs * ; } ; _bargs"

alias ls="function _ls () { /bin/ls \$COLOR -h \$* ; } ; _ls"
alias la="function _la () { /bin/ls \$COLOR -lah \$* ; } ; _la"
alias lb="function _lb () { /bin/ls \$COLOR -la \$* ; } ; _lb"
alias lr="function _lr () { /bin/ls \$COLOR -laRh \$* ; } ; _lr"
alias lt="function _lt () { /bin/ls \$COLOR -lath \$* ; } ; _lt"
alias j="jobs -l"
alias mo="more"
alias m="make"
alias m0="make OPT=O0"
alias mi="make install"
alias mc="make clean"
alias mcd="make clean_dist"
alias md="make debug"
alias ml="make log"
alias msl="make slog"
alias ms="make status"
alias mr="make run"
alias muc="make update_check"
alias mfu="make force_update"
alias mdu="make dump"
alias mre="make restart"
alias mst="make stop"
alias msa="make start"
alias men="make enable"
alias mdi="make disable"
alias mn="make -n"
alias mk="make -k"
alias mw="make --dry-run --debug=b"
alias mgit="make git"
alias syl="make syslog"
alias d="dirs"
alias pd="pushd"
alias 2="pushd +2"
alias 3="pushd +3"
alias 4="pushd +4"
alias 5="pushd +5"
alias 6="pushd +6"
alias ic="ifconfig"
alias i="ic -a"
alias df="/bin/df -h"
alias h="history"
alias z="suspend"
alias x="exit"
alias tr="traceroute"
alias al="alias"
alias soc="source ~/.profile"
alias pe="printenv"
alias cdk="cd ~/kiwi.config"
alias cdp="cd \${PROJ}"
alias cd2="cd \${PROJ2}"
alias cd3="cd \${PROJ3}"
alias jc="journalctl"
alias log="jc | tail -200"
alias pubip="curl icanhazip.com; echo"
alias ident="curl icanhazip.com; echo"
alias py="python"
alias mosd="mkdir -p /media/sd_boot; mount /dev/mmcblk1p1 /media/sd_boot"
alias umsd="umount /media/sd_boot"
alias cdsd="cd /media/sd_boot"
alias mosdr="mkdir -p /media/sd_root; mount /dev/mmcblk1p2 /media/sd_root"
alias umsdr="umount /media/sd_root"
alias cdsdr="cd /media/sd_root"
alias sshrm="function _sshrm () { sudo ssh-keygen -R \$* ; ssh-keygen -R \$* ; } ; _sshrm"
alias d+="function _d+ () { dig +short +noedns \$* A ; dig +short \$* AAAA ; } ; _d+"
alias cata="tail -vn +1 *"
alias ds="/usr/bin/du -h * | sort -hr"

alias gr="grep \$COLOR"
alias g="function _g () { gr -riI --exclude-dir .git \$* . ; } ; _g"
alias gs="function _gs () { gr -rI --exclude-dir .git \$* . ; } ; _gs"
alias g.="function _gdot () { gr -iI \$* * ; } ; _gdot"
alias gt="function _gtail () { tail -n 300 -f \$2 | gr -i --line-buffered \$1 ; } ; _gtail"
# note that only $* is required here (not \$*) perhaps due to use in built-in commands?
alias ff='function _ff () { export ffa=$* ; find . -name "*$ffa*" -print ; } ; _ff'

# file times in epoch seconds
alias lss="ls -lah --time-style=+%s"
alias dsec="function _dsec () { date --date=@\$* ; } ; _dsec"
alias dfsec="function _dfsec () { date --date=@\$* ; } ; _dfsec"

alias gbr="git branch"
alias gco="git checkout"
alias gst="git status"
alias gsh="git show"
alias grem="git remote -v"
alias gdi="git diff --no-color"
alias gclone="function _gclone () { git clone https://github.com/jks-prv/\$1.git ; } ; _gclone"

alias sc="echo systemctl: sctl scls=list_unit sclsa=list_all_units scs=service_status scsa/scst=start/stop scre=reload"
alias sctl="function _sys () { systemctl \$* ; } ; _sys"
alias scls="function _syg () { systemctl list-units | gr -i \$* ; systemctl list-unit-files | gr -i \$* ; } ; _syg"
alias sclsa="function _syg () { systemctl list-units ; systemctl list-unit-files ; } ; _syg"
alias scs="function _sys () { systemctl --lines=100 status \${*}.service ; } ; _sys"
alias scsa="function _sys () { systemctl --lines=100 start \${*}.service ; } ; _sys"
alias scst="function _sys () { systemctl --lines=100 stop \${*}.service ; } ; _sys"
alias scre="function _sys () { systemctl --lines=100 reload-or-restart \${*}.service ; } ; _sys"

alias pk="echo apt-get: s=search_available ls=list_installed i=install rm=remove au=autoremove up=update ug=upgrade c=clean sz=sizes f=which_pkg_has_file fu=file_update fi=files_installed"
alias pks="echo available pkgs:; apt-cache search"
alias pkls="echo installed pkgs:; dpkg -l | gr"
alias pkup="apt-get update"
alias pkug="apt-get upgrade"
alias pki="apt-get -y install"
alias pkc="df; apt-get clean; echo; df"
alias pksz="dpkg-query -W -f='\${Installed-Size;8}\t\${Status;1}\t\${Package}\n' | gr -v '\\sd\\s' | sort -n | cut -f1,3-"
alias pkf="apt-file search"
alias pkfu="apt-file update"
alias pkfg="apt-file upgrade"
alias pkfi="dpkg -L"
alias pkrm="apt-get purge"
#alias pkrm="apt-get remove"
alias pkau="apt-get autoremove"

# BBB
alias dog="echo Debian `cat /etc/debian_version`; more /etc/dogtag; uname -a"
alias tag=dog
alias slots7="cat /sys/devices/bone_capemgr.*/slots"
alias slots8="cat /sys/devices/platform/bone_capemgr/slots"
alias slots="cat /sys/devices/platform/bone_capemgr/slots"
alias unslot7="echo > /sys/devices/bone_capemgr.*/slots"
alias unslot8="echo > /sys/devices/platform/bone_capemgr/slots"
alias pins="more /sys/kernel/debug/pinctrl/44e10800.pinmux/pins"
alias pmux="more /sys/kernel/debug/pinctrl/44e10800.pinmux/pinmux-pins"
alias bbser="screen -h 1024 /dev/ttyUSB0 115200"
alias db="systemctl reload-or-restart dropbear.socket"
alias dk="diff -r . merge"

# KiwiSDR
alias kd="cdp; m stop; touch ~root/.kiwi_down; m start"
alias ku="cdp; m stop; rm -f ~root/.kiwi_down; m start"
alias kg="gdb kiwi.bin"
alias mu="make users"
# valgrind + gdb:
#	set non-stop off
#	handle SIGUSR2 nostop noprint
#	target remote | vgdb
alias vg="valgrind -v --track-origins=yes --leak-check=full kiwi.bin -gps"
alias vggps="valgrind -v --track-origins=yes --leak-check=full kiwi.bin"
alias vggdb="valgrind -v --track-origins=yes --leak-check=full --vgdb-error=0 kiwi.bin -gps"
alias vggdbgps="valgrind -v --track-origins=yes --leak-check=full --vgdb-error=0 kiwi.bin"
alias scD="git clone https://github.com/jks-prv/Beagle_SDR_GPS.git"
alias urldecode='sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b"'
alias wk="json_pp -t dumper <~root/kiwi.config/kiwi.json | grep rx_name | urldecode"
alias status="function _status () { curl --connect-timeout 5 \${*}:8073/status ; } ; _status"
alias status80="function _status () { curl --connect-timeout 5 \${*}:80/status ; } ; _status"
